{% extends "map/new_base.html" %}

{% comment %}

  Edit Merchant Object Page
  -------------------------
  
  This page will allow you to edit a merchant object to a marker

{% endcomment %}

{% block javascript %} 
  <xlink rel="stylesheet"  href="/assets/style/detailedit_style.css"             type="text/css" />
  <link rel="stylesheet"  href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.0/themes/humanity/jquery-ui.css"  type="text/css" />
  <style type="text/css" rel="stylesheet">
    div.ui-datepicker  {
                         font-size:11px;
                       }
  </style>


 <script src="http://www.google.com/jsapi"></script>
 
   <script type="text/javascript">
      google.load("jquery", "1");
      google.load("jqueryui", "1");  
    </script>
    


<script src="http://maps.google.com/maps?file=api&amp;v=2.147&amp;key=ABQIAAAAhcP5rdJ8gtI2Tvrvo88B3BR_tirkabJaindNc0FoauOGCOWtrBTLuwigpG4UD6tSDw3AxxYNXLmcVg" type="text/javascript"> </script>
<script type="text/javascript">
mapper = {
  load: function() {
    if (GBrowserIsCompatible()) {
      var default_lat = 52.1300;
      var default_lng = -0.2190;
      if (document.getElementById("id_lat").value.length > 0) {default_lat = document.getElementById("id_lat").value;}
      if (document.getElementById("id_lon").value.length > 0) {default_lng = document.getElementById("id_lon").value;}
      mapper.map = new GMap2(document.getElementById("map"));
      mapper.map.setCenter(new GLatLng(default_lat, default_lng), 15); // should read this out of the form if we can, cos it might be returned if the form is invalid
      mapper.map.setMapType(G_NORMAL_MAP);
      var mapControl = new GMapTypeControl();
      mapper.map.addControl(mapControl);
      mapper.map.addControl(new GLargeMapControl());
      var marker = new GMarker(new GLatLng(default_lat, default_lng),
        {draggable: true, bouncy: true, icon: G_DEFAULT_ICON, title: "New Marker"});
      
      GEvent.addListener(marker, "dragend", function() {
        mapper.map.panTo(this.getLatLng());
        document.getElementById("id_lat").value=this.getLatLng().lat();
        document.getElementById("id_lon").value=this.getLatLng().lng();
      });
      
  mapper.map.addOverlay(marker);
  mapper.map.panTo(marker.getLatLng());
  
  }
 }
}
</script>


<script type="text/javascript">
    $(document).ready(function() {
		$("#id_date_due").datepicker({ dateFormat: 'dd/mm/yy' });
		$("#id_date_ends").datepicker({dateFormat: 'dd/mm/y' });
		$("#id_freetext").resizable({'maxWidth':'725'});
    });
</script>

{% endblock %}

{% block title %}
  Potton Online  |  {% if merchobj.id %}Edit{% else %}Add{% endif%} a merchant object
{% endblock %}

{% block bodytag %}
  onload="mapper.load()" onunload="GUnload()" style="color: #000000;"
{% endblock %}


{% block page_middle %}
<div id="mainaddpoint">
<h1>{% if merchobj.id %}Edit{% else %}Add{% endif%} a merchant object</h1>
{% if form.errors %}
  ERRORS:  {{form.errors}}
{% endif %}


{% if merchobj.id %}
  <form method="POST" enctype="multipart/form-data" action="/merchant/edit/{{marker.id}}/{{merchobj.id}}">
{% else %}
  <form method="POST" enctype="multipart/form-data" action="/merchant/add/{{marker.id}}">
{% endif %}

{{form.active.errors}}
<label for="id_active" {% if form.active.errors %} class="errorlabel" {% endif %}>  {{form.active.label}}:  </label>  {{form.active}}               <br />

{{form.name.errors}}
<label for="id_name" {% if form.name.errors %} class="errorlabel" {% endif %}>  {{form.name.label}}:  </label>{{form.name}}                 <br />

{{form.merchantable_type.errors}}
<label for="id_merchantable_type" {% if form.merchantable_type.errors %} class="errorlabel" {% endif %}>  {{form.merchantable_type.label}}:  </label>{{form.merchantable_type}}    <br />

{{form.link.errors}}
<label for="id_link" {% if form.link.errors %} class="errorlabel" {% endif %}>  {{form.link.label}}:  </label>{{form.link}}                 <br />

{{form.rateable.errors}}
<label for="id_rateable" {% if form.rateable.errors %} class="errorlabel" {% endif %}>  {{form.rateable.label}}:  </label>{{form.rateable}}             <br />

{{form.commentable.errors}}
<label for="id_commentable" {% if form.commentable.errors %} class="errorlabel" {% endif %}>  {{form.commentable.label}}:  </label>{{form.commentable}}          <br />

{{form.public_email.errors}}
<label for="id_public_email" {% if form.public_email.errors %} class="errorlabel" {% endif %}>  {{form.public_email.label}}:  </label>{{form.public_email}}         <br />

{{form.public_phone.errors}}
<label for="id_public_phone" {% if form.public_phone.errors %} class="errorlabel" {% endif %}>  {{form.public_phone.label}}:  </label>{{form.public_phone}}         <br />

{{form.private_email.errors}}
<label for="id_private_email" {% if form.private_email.errors %} class="errorlabel" {% endif %}>  {{form.private_email.label}}:  </label>{{form.private_email}}        <br />

{{form.private_phone.errors}}
<label for="id_private_phone" {% if form.private_phone.errors %} class="errorlabel" {% endif %}>  {{form.private_phone.label}}:  </label>{{form.private_phone}}         <br />

{{form.freetext.errors}}
<label for="id_freetext" {% if form.freetext.errors %} class="errorlabel" {% endif %}>  {{form.freetext.label}}:  </label>{{form.freetext}}             <br />

{{form.image1.errors}}
{% if merchobj.image1 %}<img src="{{merchobj.thumbnail}}" /> {% endif %}
<label for="id_image1" {% if form.image1.errors %} class="errorlabel" {% endif %}>  {{form.image1.label}}:  </label>{{form.image1}}               <br />

{{form.price.errors}}
<label for="id_price" {% if form.price.errors %} class="errorlabel" {% endif %}>  {{form.price.label}}:  </label>{{form.price}}                <br />

{{form.description.errors}}
<label for="id_description" {% if form.description.errors %} class="errorlabel" {% endif %}>  {{form.description.label}}:  </label>{{form.description}}          <br />
  
{{form.address.errors}}
<label for="id_address" {% if form.address.errors %} class="errorlabel" {% endif %}>  {{form.address.label}}:  </label>{{form.address}}              <br />

{{form.date_due.errors}}
<label for="id_date_due" {% if form.date_due.errors %} class="errorlabel" {% endif %}>  {{form.date_due.label}}:  </label> <input type="text" name="date_due" id="id_date_due" value="{{merchobj.date_due|date:"d/m/Y"}}"/>     <br />

{{form.date_ends.errors}}
<label for="id_date_ends" {% if form.date_ends.errors %} class="errorlabel" {% endif %}>  {{form.date_ends.label}}:  </label><input type="text" name="date_ends" id="id_date_ends" value="{{merchobj.date_ends|date:"d/m/Y"}}"/>          <br />


<div id="map" style="width: 100%; height: 500px;">
</div>

<div style="display: none;">
  {{form.lat}}
  {{form.lon}}
</div>

<input type="submit" value="Submit" name="Submit" />
{% if merchobj.id %}
  <div style="display: inline;">
    Check this box to really delete this item then click Delete. 
    <input type="checkbox" value="reallydelete" name="reallydelete" style="display: inline;"/>
    <input type="submit" value="Delete" name="Delete" />
    <a href="{% url detail-edit marker.id %}">Cancel</a>
  </div>
{% endif %}
</form>
</div>
{% endblock %}
{% block page_left %}
  {% include 'map/default_pageleft.html' %}
{% endblock %}

{% block page_right %}
  {% include 'map/default_pageright.html' %}
{% endblock %}


